package cn.asterly.cicada.web.utils;


import cn.asterly.cicada.model.Sider;
import cn.asterly.cicada.service.ISiderService;
import cn.asterly.cicada.service.impl.SiderServiceImpl;
import com.google.gson.Gson;

import java.io.*;
import java.util.List;

public class GenJson {

    public static String createFile(String url, String fileName,String  data){
        File file=new File(url,fileName);
        try {
            BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(new FileOutputStream(file));
            bufferedOutputStream.write(data.getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        String fileUrl = "";
        return fileUrl;
    }

    public static void main(String[] args) {
        String url=GenJson.class.getClassLoader().getResource("").getPath();
        String name="sidernav.json";

        ISiderService siderService=new SiderServiceImpl();
        List<Sider> dada=siderService.selectByAll();
        System.out.println(url.substring(1,url.indexOf("target/classes/")));
        createFile(url,name,new Gson().toJson(dada));

    }
}
